import java.util.*;

public class CalculationSystemV03 {
    public static void main(String[] args) {
        System.out.println("加减法口算练习系统-v0.3");
        Random random = new Random();
        int total = 50;
        int addCount = total / 2; // 25道加法
        int subCount = total - addCount; // 25道减法
        int perLine = 4;

        // 用Set存储算式，自动去重
        Set<String> addEquations = new HashSet<>();
        Set<String> subEquations = new HashSet<>();

        // 生成不重复的加法算式
        while (addEquations.size() < addCount) {
            int num1 = random.nextInt(101);
            int num2 = random.nextInt(101 - num1);
            int result = num1 + num2;
            addEquations.add(String.format("%d + %d = %d", num1, num2, result));
        }

        // 生成不重复的减法算式
        while (subEquations.size() < subCount) {
            int num1 = random.nextInt(100);
            int num2 = random.nextInt(num1 + 1);
            int result = num1 - num2;
            subEquations.add(String.format("%d - %d = %d", num1, num2, result));
        }

        // 合并并打乱顺序
        List<String> allEquations = new ArrayList<>();
        allEquations.addAll(addEquations);
        allEquations.addAll(subEquations);
        Collections.shuffle(allEquations);

        // 输出
        for (int i = 0; i < allEquations.size(); i++) {
            System.out.printf("%s\t", allEquations.get(i));
            if ((i + 1) % perLine == 0) {
                System.out.println();
            }
        }
    }
}